package bairui.international.weixin.portal.miniapp.controller.order.product;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.status.State_ProductOrder;
import bairui.international.model.type.Type_ProductOrder;
import bairui.international.service.Service_ProductOrder;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *
 * 得到订单统计数据
 *
 * @generated
 * 
 * @see STest_C_Order_Product_GainStatistics_Get 测试
 *
 */
@Controller
public class C_Order_Product_GainStatistics_Get
 extends SC_Order_Product_GainStatistics_Get 
{
	
	@Autowired private Service_ProductOrder service_ProductOrder;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request,
		@RequestParam String skey
	) throws Exception {
		long paying = service_ProductOrder.count(it->it.type.eq(Type_ProductOrder.Buy).and(it.user.skey.eq(skey)).and(it.state.eq(State_ProductOrder.Paying)));
		long sending = service_ProductOrder.count(it->it.type.eq(Type_ProductOrder.Buy).and(it.user.skey.eq(skey)).and(it.state.eq(State_ProductOrder.Sending)));
		long sended = service_ProductOrder.count(it->it.type.eq(Type_ProductOrder.Buy).and(it.user.skey.eq(skey)).and(it.state.eq(State_ProductOrder.Sended)));
//		long all = service_ProductOrder.count(it->it.type.eq(Type_ProductOrder.Buy).and(it.user.skey.eq(skey)));
		return new Output(paying, sending, sended);
	}
	
	@AllArgsConstructor
	private class Output {
		private @Getter Long paying;	// 待付款
		private @Getter Long sending;	// 待发货
		private @Getter Long sended;	// 已发货
//		private @Getter Long all;		// 全部
	}
	
}
